Generated code - QuerySpec, Specifying the type of a DynamicQuery resultset

A dynamic query is an un-typed projection of data. In the raw form, this query is returned in a list of object arrays. To have a typed projection, the a projectior func has to be specified. This can be done in two ways:

  1. Use the DynamicQuery.WithProjector<T>(Func<ProjectionRow, T> projectorFunc) method. The Func specified receives a ProjectionRow object, and converts it into an instance of type T. The WithProjector method returns a DynamicQuery<T> instance, instead of a DynamicQuery instance.
  2. Use the Query.Select(Expression<Func<T>> projection) method. This method is equal to query.Select(projection) where projection is one or more elements, however the projection lambda is converted into a Func<ProjectionRow, T> internally.

Fetching a DynamicQuery uses a projection fetch, so type converters and the like are taken into account.

A Dynamic query can be returned as one of the following result types:

Examples

Below are three ways to define the same dynamic query. qf is the QueryFactory instance.

DynamicQuery, returning List<object[]>
var q = qf.Order
	 .Where(OrderFields.CustomerId.StartsWith("C"))
	 .OrderBy(OrderFields.CustomerId.Ascending())
	 .Select(OrderFields.OrderId, OrderFields.CustomerId, OrderFields.EmployeeId, OrderFields.OrderDate)
DynamicQuery<T>, using WithProjector<T>, returning List<T>
var q = qf.Order
	 .Where(OrderFields.CustomerId.StartsWith("C"))
	 .OrderBy(OrderFields.CustomerId.Ascending())
	 .Select(OrderFields.OrderId, OrderFields.CustomerId, OrderFields.EmployeeId, OrderFields.OrderDate)
	 .WithProjector(r => new
	 {
		 OrderId = (int)r[0],
		 CustomerId = (string)r[1],
		 EmployeeId = (int?)r[2],
		 OrderDate = (DateTime?)r[3]
	 });
DynamicQuery<T>, using .Select(Expression<Func<>>), returning List<T>
var q = qf.Order
	.Where(OrderFields.CustomerId.StartsWith("C"))
	.OrderBy(OrderFields.CustomerId.Ascending())
	.Select(() => new
	{
		OrderId = OrderFields.OrderId.ToValue<int>(),
		CustomerId = OrderFields.CustomerId.ToValue<string>(),
		EmployeeId = OrderFields.EmployeeId.ToValue<int?>(),
		OrderDate = OrderFields.OrderDate.ToValue<DateTime?>()
	});

LLBLGen Pro Runtime Framework v3.5 documentation. ©2012 Solutions Design bv